/***************************************************
  This is our library for the Adafruit  ILI9341 Breakout and Shield
  ----> http://www.adafruit.com/products/1651

  Check out the links above for our tutorials and wiring diagrams
  These displays use SPI to communicate, 4 or 5 pins are required to
  interface (RST is optional)
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 ****************************************************/

#ifndef __ILI9341_H
#define __ILI9341_H

#include "ili9341_drv.h"

#define ILI9341_NOP     0x00
#define ILI9341_SWRESET 0x01
#define ILI9341_RDDID   0x04
#define ILI9341_RDDST   0x09

#define ILI9341_SLPIN   0x10
#define ILI9341_SLPOUT  0x11
#define ILI9341_PTLON   0x12
#define ILI9341_NORON   0x13

#define ILI9341_RDMODE  0x0A
#define ILI9341_RDMADCTL  0x0B
#define ILI9341_RDPIXFMT  0x0C
#define ILI9341_RDIMGFMT  0x0D
#define ILI9341_RDSELFDIAG  0x0F

#define ILI9341_INVOFF  0x20
#define ILI9341_INVON   0x21
#define ILI9341_GAMMASET 0x26
#define ILI9341_DISPOFF 0x28
#define ILI9341_DISPON  0x29

#define ILI9341_CASET   0x2A
#define ILI9341_PASET   0x2B
#define ILI9341_RAMWR   0x2C
#define ILI9341_RAMRD   0x2E

#define ILI9341_PTLAR   0x30
#define ILI9341_MADCTL  0x36
#define ILI9341_PIXFMT  0x3A

#define ILI9341_FRMCTR1 0xB1
#define ILI9341_FRMCTR2 0xB2
#define ILI9341_FRMCTR3 0xB3
#define ILI9341_INVCTR  0xB4
#define ILI9341_DFUNCTR 0xB6

#define ILI9341_PWCTR1  0xC0
#define ILI9341_PWCTR2  0xC1
#define ILI9341_PWCTR3  0xC2
#define ILI9341_PWCTR4  0xC3
#define ILI9341_PWCTR5  0xC4
#define ILI9341_VMCTR1  0xC5
#define ILI9341_VMCTR2  0xC7

#define ILI9341_RDID1   0xDA
#define ILI9341_RDID2   0xDB
#define ILI9341_RDID3   0xDC
#define ILI9341_RDID4   0xDD

#define ILI9341_GMCTRP1 0xE0
#define ILI9341_GMCTRN1 0xE1

// Color definitions
// 	Consultar documento:  D:\meus_conhecimentos\videos & imagens\RGB color table.docx
#define clBlack       0x0000      //   0,   0,   0
#define clNavy        0x000F      //   0,   0, 128
#define clDarkGreen   0x03E0      //   0, 128,   0
#define clDarkCyan    0x03EF      //   0, 128, 128
#define clMaroon      0x7800      // 128,   0,   0
#define clPurple      0x780F      // 128,   0, 128
#define clOlive       0x7BE0      // 128, 128,   0
#define clLightGrey   0xC618      // 192, 192, 192
#define clDarkGrey    0x7BEF      // 128, 128, 128
#define clBlue        0x001F      //   0,   0, 255
#define clGreen       0x07E0      //   0, 255,   0
#define clCyan        0x07FF      //   0, 255, 255
#define clRed         0xF800      // 255,   0,   0
#define clMagneta     0xF81F      // 255,   0, 255
#define clYellow      0xFFE0      // 255, 255,   0
#define clWhite       0xFFFF      // 255, 255, 255
#define clOrange      0xFD20      // 255, 165,   0
#define clGreenYellow 0xAFE5      // 173, 255,  47
#define clPink        0xF81F

void tft_Init(void);
#if (ILI9341_USE_RESET == pdON)
void tft_Reset(void);
#endif
void tft_WriteCommand(u8 c);
void tft_WriteData(u8 c);
u8 tft_ReadData(void);
u8 tft_ReadCommand(u8 c);

void tft_SetAddrWindow(u16 x0, u16 y0, u16 x1, u16 y1);
void tft_PushColor(u16 color);
void tft_DrawPixel(s16 x, s16 y, u16 color);
void tft_DrawFastVLine(s16 x, s16 y, s16 h, u16 color);
void tft_DrawFastHLine(s16 x, s16 y, s16 w, u16 color);
void tft_FillScreen(u16 color);
void tft_FillRect(s16 x, s16 y, s16 w, s16 h, u16 color);
u16 tft_Color565(u8 r, u8 g, u8 b);
void tft_SetRotation(u8 m);
void tft_InvertDisplay(uint i);
u16 tft_Height(void);
u16 tft_Width(void);

#endif
